From 988c0cb02e12e5a6d7f5efdbb9a8186b4aa34cad Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Fri, 3 Mar 2006 15:32:42 +0100 Subject: [PATCH] Cope when the filename returned by losetup for an existing loop device is not fully qualified. In this case, the readlink -f call to canonicalise that name fails. Closes bug #553. Signed-off-by: Ewan Mellor --- tools/examples/block | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tools/examples/block b/tools/examples/block index e73ab9c8bf..5a43560eff 100644 --- a/tools/examples/block +++ b/tools/examples/block @@ -321,7 +321,28 @@ mount it read-write in a guest domain." fi fi - f=$(readlink -f "$f") + # Canonicalise the filename for the comparison. + + # I have seen this readlink fails because the filename given by + # losetup is only the basename. This cannot happen when the loop + # device is set up through this script, because file is + # canonicalised above, but it may happen when loop devices are set + # up some other way. This readlink may also conceivably fail if + # the file backing this loop device has been removed. + + # For maximum safety, in the case that $f does not resolve, we + # assume that $file and $f are in the same directory. + + # If you create a loopback filesystem, remove it and continue to + # run on it, and then create another file with the same name, then + # this check will block that -- don't do that. + + # If you create loop devices through some other mechanism, use + # relative filenames, and then use the same filename through this + # script, then this check will block that -- don't do that either. + + f=$(readlink -f "$f" || echo $(dirname "$file")/$(basename "$f")) + if [ "$f" == "$file" ] then -- 2.30.2